package com.example;

import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author Create By Liuqz
 * @date 2018/11/16 14:26
 */
public class NumericStream {


    public static void main(String[] args) {
        /*Stream<Integer> stream = Arrays.stream(new Integer[]{1,2,3,4,5,6,7,8});

        IntStream intStream = stream.mapToInt(i -> i.intValue());

        int result = intStream.filter(i -> i > 3).sum();

        int res = stream.mapToInt(i -> i.intValue()).filter(i -> i>3).sum();

        System.out.println(result);*/


//        int a = 9;
//
//        IntStream.rangeClosed(1, 1000)
//                .filter(b -> Math.sqrt(a * a + b * b) % 1 == 0)
//                .boxed()
//                .map(b -> new int[]{a, b, (int) Math.sqrt(a * a + b * b)})
//                .forEach(r -> System.out.println("a=" + r[0] + "b=" + r[1] + "c=" + r[2]));
//
//        System.out.println("==============================================");
//
//
//        IntStream.rangeClosed(1, 1000)
//                .filter(b -> Math.sqrt(a * a + b * b) % 1 == 0)
//                .mapToObj(b -> new int[]{a, b, (int) Math.sqrt(a * a + b * b)})
//                .forEach(r -> System.out.println("a=" + r[0] + "b=" + r[1] + "c=" + r[2]));


        Stream<int[]> types = IntStream.rangeClosed(1,1000).boxed()
                .flatMap(a -> IntStream.rangeClosed(a,1000)
                .filter(b -> Math.sqrt(a *a + b *b) %1 ==0)
                .mapToObj(b -> new int[]{a,b,(int)Math.sqrt(a *a + b *b)}));

        types.forEach(t -> System.out.println(t[0]+","+t[1]+","+t[2]));
    }
}
